<template>
	<view class="bg" :style="'background-image: url('+WEBCONFIG.bg2+');'">
		<!-- #ifndef MP-TOUTIAO -->
		<uni-nav-bar status-bar title="奖励" color='#fff' backgroundColor="none" :border='false'></uni-nav-bar>
		<!-- #endif -->
		<view class="flex flex-row flex-y-center ml-4">
			<image src="../../static/icon/share_active.png" class="money"></image>
			<view class="text-white h7 font-weight-800">完成任务获取次数</view>
		</view>
		<view class="p-4">
			<view class="p-4 box-shadow rounded-3 bg-white">
				<view class="flex flex-column">
					<view class="text-dark-light-2 ">日常任务</view>
					<view class="flex flex-row flex-y-center mt-4 mb-3" @click="playAd" v-if="WEBCONFIG?.douyin_incentive_status==1">
						<view class="w-90">
							<view class="text-dark-light-1 mb-2">观看视频</view>
							<view class="h9 text-dark-light-4 mb-2">快速免费获得搜题次数</view>
						</view>
						<uni-icons type="right" size="20"></uni-icons>
					</view>
					<view class="line"></view>
					<button class="btn-normal" open-type="share">
						<view class="flex flex-row flex-y-center mt-4 mb-3">
							<view class="w-90">
								<view class="text-dark-light-1 mb-2">分享好友</view>
								<view class="h9 text-dark-light-4 mb-2">分享好友，获得次数</view>
							</view>
							<uni-icons type="right" size="20"></uni-icons>
						</view>
					</button>
					<view class="line"></view>

					<view class="flex flex-row flex-y-center mt-4 mb-3"
						@click="$page.open('/pages/article/index?name=account')">
						<view class="w-90">
							<view class="text-dark-light-1 mb-2">关注公众号</view>
							<view class="h9 text-dark-light-4 mb-2">公众号入口进入</view>
						</view>
						<uni-icons type="right" size="20"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad mt-9" v-if="WEBCONFIG.weixin_banner_status && WEBCONFIG.weixin_banner_status == 1">
			<ad :unit-id="WEBCONFIG.weixin_banner_ad_id" ad-theme="white"></ad>
		</view>
		<!-- #endif -->

		<!-- #ifdef MP-TOUTIAO -->
		<view class="ad mt-9" v-if="WEBCONFIG.douyin_banner_status && WEBCONFIG.douyin_banner_status == 1">
			<ad :unit-id="WEBCONFIG.douyin_banner_ad_id" ad-theme="white"></ad>
		</view>
		<!-- #endif -->

		<x-tabbar page="/pages/reward/index"></x-tabbar>

	</view>
</template>

<script setup lang="ts">
	import { useUserStore, useWebConfigStore, useRefs } from "@/stores";
	import { onLoad, onShareAppMessage } from "@dcloudio/uni-app";
	import { useStorage, $http, $page } from '@/utils'
	import { initAd } from '@/utils/ad'
	//站点信息
	const webConfigStore = useWebConfigStore()
	const { WEBCONFIG } = useRefs(webConfigStore);
	const storage = useStorage()
	//用户信息
	const userStore = useUserStore()
	const { USERINFO } = useRefs(userStore);
	let ad : any;
	onLoad(() => {
		ad = initAd();
		uni.hideTabBar();
	})

	//播放视频
	const playAd = (() => {
		uni.showModal({
			title: '提示',
			content: '是否播放激励广告?',
			success(res : any) {
				if (res.confirm == true) {
					$http.get('User/isPoints').then((result : any) => {
						if (result.data == true) {
							ad.show().then((status : any) => {
								if (status && status.isEnded || status === undefined) {
									$http.get('User/addPoints').then(res => {
										USERINFO.value.points += 1
										userStore.setUserInfo(USERINFO.value)
										uni.showToast({
											title: '增加次数成功',
											icon: 'none'
										})
									})
								}
							})
						} else {
							uni.showToast({
								title: '今日观看次数已达上限',
								icon: 'none'
							})
						}
					})
				}
			}
		})

	})
	//分享
	onShareAppMessage(() => {
		return $page.shareTimeline({
			path: '/pages/index/index'
		})
	})
</script>

<style>
	.bg {
		width: 100%;
		background-repeat: no-repeat;
		background-size: 100%;
	}

	.line {
		height: 1px;
		background-color: #e2e2e2;
		width: 100%;
	}

	.money {
		width: 120rpx;
		height: 120rpx;
	}
</style>